package com.simplemvc.core.util;
import com.simplemvc.core.vo.Actions;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
 * 
 * @author 王海
 */
public class XmlBeanConverter {
    
    public static final XStream xstream;
    
    static {
        xstream = new  XStream(new DomDriver("UTF-8"));
    }
    
    public static  <T> T xml2Bean(String xmlPath,Class<T> clazz) throws InstantiationException, IllegalAccessException{
      xstream.processAnnotations(clazz);
      return  (T) xstream.fromXML(Actions.class.getClassLoader().getResourceAsStream(xmlPath));
    }
    
    public static void main(String[] args) {
        try {
            xml2Bean("simplemvc.xml", Actions.class);
        } catch (Exception ex) {
            ex.printStackTrace();;
        }
    }
}
